{template 'common/header'}
{php echo $this -> set_tabbar($action);}
<div class="main">
        <form action="" method="post" onsubmit="return check();" class="form-horizontal form" enctype="multipart/form-data">
        <h4>{$title} - <a href="{php echo create_url('site/module', array('do' => 'SetRule', 'name' => 'icard'));}" style="font-size:0.8em">入口设置</a></h4>
        <input type="hidden" id="id" name="id" value="{$reply['id']}"/>
		<table class="tb">
			<tr>
				<th><label for="">标题</label></th>
				<td>
                    <input type="text" name="title" value="{$reply['title']}" id="title" class="span4" placeholder="请输入标题"/>
                    <div class="help-block">不超过30个字符</div>
				</td>
			</tr>
            <tr>
                <th><label for="">选择人群</label></th>
                <td>
                    <label class="radio inline">
                        <input type="checkbox" name="levelids[]" value="0" {if in_array(0, $levelarr)}checked{/if}> 所有会员
                    </label>
                    {loop $levels $level}
                    <label class="radio inline">
                        <input type="checkbox" name="levelids[]" value="{$level['id']}" {if in_array($level['id'], $levelarr)}checked{/if}> {$level['levelname']}
                    </label>
                    {/loop}
                </td>
            </tr>
            <tr>
                <th><label for="">使用次数</label></th>
                <td>
                    <input type="text" name="count" value="{if empty($reply)}0{else}{$reply['count']}{/if}" id="count" class="span1" /> 设为0表示不限次数
                </td>
            </tr>
            <tr>
                <th><label for="">有效期</label></th>
                <td>
                    <link type="text/css" rel="stylesheet" href="./resource/style/daterangepicker.css?v={TIMESTAMP}" />
                    <script type="text/javascript" src="./resource/script/daterangepicker.js?v={TIMESTAMP}"></script>
                    <input name="starttime" type="hidden" value="{php echo date('Y-m-d H:i', $starttime)}" />
                    <input name="endtime" type="hidden" value="{php echo date('Y-m-d H:i', $endtime)}" />
                    <button class="btn" id="date-range" class="date" type="button"><span class="date-title">{php echo date('Y-m-d H:i:s', $starttime)} 至 {php echo date('Y-m-d  H:i:s', $endtime)}</span> <i class="icon-caret-down"></i></button>
                </td>
            </tr>
			<tr>
				<th><label for="">使用说明</label></th>
				<td>
                    <textarea style="height:200px; width:600px;" class="richtext-clone" name="content" id="content">{$reply['content']}</textarea>
				</td>
			</tr>
            <tr>
                <th><label for="">排序</label></th>
                <td>
                    <input type="text" name="displayorder" value="{if empty($reply)}0{else}{$reply['displayorder']}{/if}" id="displayorder" class="span1" />
                </td>
            </tr>
			<tr>
				<th></th>
				<td>
					<input name="submit" type="submit" value="提交" class="btn btn-primary span3">
					<input type="hidden" name="token" value="{$_W['token']}" />
				</td>
			</tr>
		</table>
	</form>
</div>
<script type="text/javascript">
        function check() {
            if($.trim($('#title').val()) == '') {
                message('没有输入标题.', '', 'error');
                return false;
            }
            if($.trim($('#title').val()).length > 30) {
                message('标题不能多于30个字.', '', 'error');
                return false;
            }
            return true;
        }
        </script>
<script type="text/javascript">
    kindeditor($('.richtext-clone'));
    kindeditorUploadBtn($('#btnpicture'));
</script>
<script type="text/javascript">
    $('#date-range').daterangepicker({
        format: 'YYYY-MM-DD H:m',
        startDate: $(':hidden[name=starttime]').val(),
        endDate: $(':hidden[name=endtime]').val(),
        startTime:$(':hidden[name=starttime]').val(),
        endTime:$(':hidden[name=endtime]').val(),
        locale: {
            applyLabel: '确定',
            cancelLabel: '取消',
            fromLabel: '从',
            toLabel: '至',
            weekLabel: '周',
            customRangeLabel: '日期范围',
            daysOfWeek: moment()._lang._weekdaysMin.slice(),
            monthNames: moment()._lang._monthsShort.slice(),
            firstDay: 0
        }
    }, function(start, end){
        $('#date-range .date-title').html(start.format('YYYY-MM-DD H:m') + ' 至 ' + end.format('YYYY-MM-DD H:m'));
        $(':hidden[name=starttime]').val(start.format('YYYY-MM-DD H:m'));
        $(':hidden[name=endtime]').val(end.format('YYYY-MM-DD H:m'));
    });
</script>
{template 'common/footer'}
